package com.bestom.waterquality.logic;

import android.content.Context;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AlertDialog;

import com.bestom.waterquality.R;
import com.bestom.waterquality.util.CommandExec;

/**
 * 重启设置
 */
public class Reboot {

    private Context mContext;

    private Reboot() {
    }

    private static Reboot _instance = null;

    public static Reboot getInstance() {
        if (_instance == null)
            _instance = new Reboot();
        return _instance;
    }

    public void setDataAndListen(Context context, View view){

        if (mContext == null){
            mContext = context;
            /*
             * 重启
             * */
            view.findViewById(R.id.reboot).setOnClickListener(v -> new AlertDialog.Builder(mContext)
                    .setTitle("重启系统")
                    .setMessage("您确定要重启系统吗？")
                    .setPositiveButton("确定", (dialog, which) -> {
                        CommandExec.CommandResult commandResult = CommandExec.execCommand("reboot", false);
                        Log.i("//cs", "reboot  " + commandResult.result + "  errorMsg:" + commandResult.errorMsg + "  successMsg:" + commandResult.successMsg);
                    })
                    .setNegativeButton("取消", null)
                    .show());
        }
    }
}
